# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import List
from fastapi import APIRouter, Request, Depends
from hypertext import R, response_json, PagingResult
from apps.api.schemas.agent.mcp import client_schema as schema
from apps.api.service.agent.mcp.client_service import McpClientService

router = APIRouter(prefix="/client", tags=["MCP服务接口"])


@router.get("/whole", summary="全部MCP", response_model=R[PagingResult[schema.McpWholeVo]])
@response_json
async def whole(request: Request, params: schema.McpWholeIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await McpClientService.whole(user_id, params)


@router.post("/get_tools", summary="获取工具", response_model=R[List[dict]])
@response_json
async def get_tools(params: schema.McpParserIn):
    return await McpClientService.get_tools(params.url)


@router.post("/call_tool", summary="调用工具", response_model=R)
@response_json
async def call_tool(params: schema.McpCallIn):
    return await McpClientService.call_tool(params)


@router.get("/lists", summary="MCP列表", response_model=R[PagingResult[schema.McpListVo]])
@response_json
async def lists(request: Request, params: schema.McpSearchIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await McpClientService.lists(params, user_id)


@router.get("/detail", summary="MCP详情", response_model=R[schema.McpDetailVo])
@response_json
async def detail(request: Request, params: schema.McpCodeIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await McpClientService.detail(params.code, user_id)


@router.post("/add", summary="MCP新增", response_model=R)
@response_json
async def add(request: Request, params: schema.McpAddIn):
    user_id: int = int(request.state.user_id)
    return await McpClientService.add(params, user_id)


@router.post("/edit", summary="MCP新增", response_model=R)
@response_json
async def edit(request: Request, params: schema.McpEditIn):
    user_id: int = int(request.state.user_id)
    return await McpClientService.edit(params, user_id)


@router.post("/delete", summary="MCP删除", response_model=R)
@response_json
async def delete(request: Request, params: schema.McpCodeIn):
    user_id: int = int(request.state.user_id)
    return await McpClientService.delete(params.code, user_id)
